package com.zjcode.cdcer.service.impl;

import com.chinatechstar.component.commons.entity.MPage;
import com.chinatechstar.component.commons.result.PaginationBuilder;
import com.chinatechstar.component.commons.service.BaseService;
import com.chinatechstar.component.commons.supports.PageData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zjcode.cdcer.mapper.CerCasUsersyncinfoMapper;
import com.zjcode.cdcer.model.CerCasUsersyncinfo;
import com.zjcode.cdcer.service.CerCasUsersyncinfoService;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName:CerCasUsersyncinfoServiceImpl
 * @功能：
 * @author：wlei
 * @日期：2023/2/7-00:59
 **/
@Service
@Slf4j
public class CerCasUsersyncinfoServiceImpl implements CerCasUsersyncinfoService, BaseService {

    @Autowired
    private CerCasUsersyncinfoMapper cerCasUsersyncinfoMapper;

    @Override
    public Map<String, Object> listByPage(PageData pageData) {
        MPage mPage = getPageInfo(pageData);
        Page<Object> page = PageHelper.startPage(mPage.getCurrentPage(), mPage.getPageSize());
        List<LinkedHashMap<String, Object>> list = new ArrayList<>();
        list.addAll(cerCasUsersyncinfoMapper.listByPage(pageData));
        return PaginationBuilder.buildResult(list,
                                             page.getTotal(),
                                             mPage.getCurrentPage(),
                                             mPage.getPageSize());
    }

    @Override
    public int queryAllUnInitSysuserCount() {
        log.info("查询所有未被同步到系统用户表的用户数量");
        return cerCasUsersyncinfoMapper.countByIsInitSysuser(0);
    }

    @Override
    public CerCasUsersyncinfo findUserById(String id) {
        return cerCasUsersyncinfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(CerCasUsersyncinfo record) {
        return cerCasUsersyncinfoMapper.updateByPrimaryKeySelective(record);
    }
}
